home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byt86aug.arc / LETS.SRC < prev    next >
Text File  |  1980-01-01  |  6KB  |  275 lines

  1. /* ====  Byte Benchmark: Eratosthenes Sieve    
  2.                   02-22-86  WGW  ====    */
  3.  
  4. #define ITERATIONS 10    /* number of times to 
  5.                            perform test    */
  6.  
  7. #define LOCAL    1  /* use stack for flags  */
  8. #define GLOBAL    0  /* use global area for flags */
  9.  
  10. typedef char flag ; /* different types make a 
  11.                        difference    */
  12.  
  13.  
  14. #include <stdio.h>  /* standard I/O definitions    */
  15.  
  16.  
  17. /* ----  Main Function  ----    */
  18.  
  19. #define SIZE    7000
  20.  
  21. #if    GLOBAL
  22. flag flags [ SIZE + 1 ] ;    /* prime number flag array    */
  23. #endif
  24.  
  25.  
  26. main ()
  27. {
  28.   /* ----  Variable definitions  ----    */
  29.   /*                    */
  30.   /* Note: only some register specifications will 
  31.      be used due to the    */
  32.   /* limited number of registers available.  
  33.      Normally, the first    */
  34.   /* items are allocated to registers.    */
  35.  
  36.   register int i ;   /* ordered by preference    */
  37.   register int k ;
  38.   register int prime ;
  39.   register int count ;
  40.   register int iterations ;
  41.  
  42. #if    LOCAL
  43.            flag flags [ SIZE + 1 ] ;    
  44.            /* prime number flag array    */
  45. #endif
  46.  
  47.  
  48.   /* ----  Show off start of execution  ---- */
  49.  
  50.   printf ( "Starting Eratosthenes Sieve 
  51.             Benchmark\n\n" ) ;
  52.   printf ( "%d iterations.\n\n", ITERATIONS ) ;
  53.  
  54.  
  55.   for ( iterations = ITERATIONS ; iterations ; -- 
  56.         iterations )
  57.   {
  58.     /* ----  Initialize Sieve Flag Array  ---- */
  59.  
  60.     for ( i = 0 ; i < SIZE ; ++ i )
  61.       flags [ i ] = 1 ;    /* mark all as prime numbers  */
  62.  
  63.  
  64.     /* ----  Search for Prime Numbers  ----          */
  65.  
  66.     for (   i     = 0    /* scan for next prime number    */
  67.           , count = 0    /* keep count of primes found    */
  68.         ; i < SIZE
  69.         ; ++ i
  70.         )
  71.       if ( flags [ i ] != 0 ) /* check if prime found    */
  72.       {
  73.         /* ---- Prime found.  Count it and unmark 
  74.                 multiples  ----    */
  75.  
  76.         ++ count ; /* increment number of primes    */
  77.  
  78.         for (   prime = i + i + 3    
  79.                 /* mark multiples as non-prime    */
  80.               , k     = i + prime    
  81.                 /* start with first multiple    */
  82.             ; k < SIZE
  83.             ; k += prime
  84.             )
  85.           flags [ k ] = 0 ;   
  86.            /* reset multiples to non-prime    */
  87.       }
  88.   }
  89.  
  90.  
  91.   /* ----  Mark end of execution  ----        */
  92.  
  93.   printf ( "%d prime numbers found.\n", count ) ;
  94.  
  95.   printf ( "End of Test\n\n" ) ;
  96. }
  97.  
  98.  
  99. /* ====  End of Eratosthenes Sieve Benchmark  ==== */
  100. .pa
  101. /* ====  Byte Benchmark: Calculation Test 02-22-86 WGW ==== */
  102.  
  103. #include <stdio.h>    /* standard I/O definitions */
  104.  
  105.  
  106. /* ====  Main Function  ====    */
  107.  
  108. #define ITERATIONS    5000
  109.  
  110. main ()
  111. {
  112.   float a, b, c ;
  113.   int   i ;
  114.  
  115.  
  116.   /* ----  Show start of test  ----  */
  117.  
  118.   printf ( "Start of Calculation Test.\n\n" ) ;
  119.  
  120.  
  121.   /* ----  Perform test loop  ----  */
  122.  
  123.   for (   i = ITERATIONS  /* setup for timing loop  */
  124.         , a = 2.71828
  125.         , b = 3.14159
  126.         , c = 1
  127.       ; i                  /* exit when end of test    */
  128.       ; -- i
  129.       )
  130.   {
  131.   /* ---- Perform balanced set of calculations ----  */
  132.  
  133.     c *= a ;    /* same as c = c * a        */
  134.     c *= b ;
  135.  
  136.     c /= a ;    /* same as c = c / a        */
  137.     c /= b ;
  138.   }
  139.  
  140.  
  141.   /* ----  Show end of test  ----        */
  142.  
  143.   printf ( "End of test.  Accumulated error: 
  144.             %f\n\n", c - 1 ) ;
  145. }
  146.  
  147.  
  148. /* ====  End of Eratosthenes Sieve Benchmark  ====  */
  149. .pa
  150. /* ====  Byte Benchmark: Write 64 kbyte file    
  151.          02-22-86  WGW  ====    */
  152.  
  153. #include <stdio.h>   /* standard I/O definitions  */
  154.  
  155.  
  156. /* ====  Main Test Function   ====               */
  157.  
  158. #define RECORDS    512  /* records in test file     */
  159. #define REC_SIZE    128    /* size of records, 
  160.                                    total is 64kbyes  */
  161.  
  162. main ()
  163. {
  164.          int  file ;
  165.          int  records ;
  166.          char buffer [ REC_SIZE ] ;
  167.  
  168.          int  i ;    /* buffer fill index    */
  169.  
  170.   static char file_name [] = "B:TEST" ;
  171.  
  172.  
  173.   /* ----  Show start of test  ----        */
  174.  
  175.   printf ( "Writing TEST file.\n\n" ) ;
  176.  
  177.  
  178.   /* ----  Fill output buffer with recognizable 
  179.                       information  ----    */
  180.  
  181.   for ( i = 0 ; i < sizeof ( buffer ) ; ++ i )
  182.     buffer [ i ] = i ;
  183.  
  184.  
  185.   /* ----  Write information  ----        */
  186.  
  187.   if (( file = creat ( file_name, 0 )) > -1 )
  188.   {
  189.     /* ---- File opened, try writing all the records ---- */
  190.  
  191.     for ( records = RECORDS ; records ; -- records )
  192.       if ( write ( file, buffer, sizeof ( buffer )) != 
  193.       sizeof ( buffer ))
  194.       {
  195.         printf ( "Write error.\n" ) ; /* show error  */
  196.         break ;            /* exit from loop  */
  197.       }
  198.  
  199.  
  200.     /* ----  Close down the file  ----    */
  201.  
  202.     close ( file ) ;
  203.   }
  204.   else
  205.     printf ( "Cannot open %s\n", file_name ) ;
  206.  
  207.  
  208.   /* ----  Show end of test  ----    */
  209.  
  210.   printf ( "End of Write Test.\n\n" ) ;
  211. }
  212.  
  213.  
  214. /* ==== End of Write 64 kbyte File Benchmark ==== */
  215.  
  216. .pa
  217.  
  218. /* ====  Byte Benchmark: Read 64 kbyte file    
  219.               02-22-86  WGW  ====    */
  220.  
  221. #include <stdio.h>  /* standard I/O definitions  */
  222.  
  223.  
  224. /* ====  Main Test Function   ====    */
  225.  
  226. #define RECORDS      512    /* records in test file  */
  227. #define REC_SIZE  128    /* size of records, 
  228.                            total is 64kbyes    */
  229.  
  230. main ()
  231. {
  232.          int  file ;
  233.          int  records ;
  234.          char buffer [ REC_SIZE ] ;
  235.   static char file_name [] = "B:TEST" ;
  236.  
  237.  
  238.   /* ----  Show start of test  ----  */
  239.  
  240.   printf ( "Reading TEST file.\n\n" ) ;
  241.  
  242.  
  243.   /* ----  Read information  ----  */
  244.  
  245.   if (( file = open ( file_name, 0 )) > -1 )
  246.   {
  247.     /* ---- File opened, try reading all the records ---- */
  248.  
  249.     for ( records = RECORDS ; records ; -- records )
  250.       if ( read ( file, buffer, sizeof ( buffer )) != 
  251.            sizeof ( buffer ))
  252.       {
  253.         printf ( "Read error.\n" ) ;/* show error */
  254.         break ;                /* exit from loop */
  255.       }
  256.  
  257.  
  258.     /* ----  Close down the file  ----    */
  259.  
  260.     close ( file ) ;
  261.   }
  262.   else
  263.     printf ( "Cannot open %s\n", file_name ) ;
  264.  
  265.  
  266.   /* ----  Show end of test  ---- */
  267.  
  268.   printf ( "End of Read Test.\n\n" ) ;
  269. }
  270.  
  271.  
  272. /* ====  End of Read 64 kbyte File Benchmark  ====  */
  273.  
  274.  
  275.